package com.ensa.googlemapsandroidv2;

import com.ensa.googlemapsandroidv2.R;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Authentification extends Activity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.authentication);
		
		final Button loginBtn = (Button) findViewById(R.id.loginBtn);
		
		/******** Dynamically create view elements **********/
		
		loginBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				EditText login = (EditText) findViewById(R.id.unameTxt);
				EditText pass = (EditText) findViewById(R.id.passTxt);
				
				if(login.getText().toString().equals("ennaji") && pass.getText().toString().equals("pass")){
					Intent i = new Intent(getBaseContext(), ModificationDonnee.class);
					Bundle extra = getIntent().getExtras();
					String nom = extra.getString("nom");
					String adresse = extra.getString("adresse");
					String tel = extra.getString("tel");
					String age = extra.getString("age");
					String position = extra.getString("position");
					
					
					i.putExtra("nom",nom);
					i.putExtra("age",age);
					i.putExtra("adresse",adresse);
					i.putExtra("tel",tel);
					i.putExtra("position",position);
					
					startActivity(i);
				}
				else{
					Context context = getApplicationContext();
					CharSequence text = "Login ou mot de passe incorrect";
					int duration = Toast.LENGTH_SHORT;
					Toast toast = Toast.makeText(context, text, duration);
					toast.show();
				}
			}
		});
	}

}
